﻿
<script type="text/javascript">
    //2018-12-06 zch
    function deletePayInRow() {
        $('#PayInID').val('');
        $('#txtPayTime').datebox('clear');
        $('#txtSubmitTime').datebox('clear'); //add20190613 plq 凭证上交日期

        $('#txtPayNumber').textbox('clear');
        $('#txtPayPerson').textbox('clear');
        $('#txtPayRemark').textbox('clear');

        $('#txtAmountPayable').numberbox('clear');
        $('#txtPayMoney').numberbox('clear');
        $('#txtUnPaidMoney').numberbox('clear');

        $('#txtAmountPayable').numberbox('readonly', false);
        $('#txtPayMoney').numberbox('readonly', false);
        $('#txtUnPaidMoney').numberbox('readonly', false);

        $("#timeOut").html("");
        $('#txtPayTime').datebox('readonly', false);
        $('#txtSubmitTime').datebox('readonly', false);//add20190613 plq 凭证上交日期
        $('#txtPayNumber').textbox('readonly', false);
        $('#txtPayPerson').textbox('readonly', false);
        $('#txtPayRemark').textbox('readonly', false);
    }

    //打开解款弹层页---参数：当前列表数据行的ID
    function openPayInDialog(drID) {
        $("#ReportPayIn").dialog("open");
        //根据ID 获取是否填写过解款
        $('#PayInID').val(drID);

        $('#txtPayMoney').numberbox({   //解款金额数字框
            onChange: function (oldV, newV) {
                var x = $('#txtAmountPayable').numberbox('getValue');  //应解金额
                var y = $('#txtPayMoney').numberbox('getValue');
                //if (Number(y) <= Number(x)) {
                //    var z = Number(x) - Number(y);
                //    $('#txtUnPaidMoney').numberbox('setValue', z);
                //} else {
                //    $('#txtUnPaidMoney').numberbox('setValue', 0);
                //}

                //2019-06-13 plq add 未缴金额如果<0正常显示负数
                var z = Number(x) - Number(y);
                $('#txtUnPaidMoney').numberbox('setValue', z);   //应解未缴
            }
        });

        $.ajax({
            type: 'POST',
            url: '@Url.Content("~/DD/DriverReport/GetPayByCode")', //获取初始信息
            data:
                {
                    RowID: $('#PayInID').val()
                },
            dataType: "json",
            success: function (jsData) {
                if (jsData.Result == "OK") {
                    $('#txtPayTime').datebox('setValue', $.formatDate(jsData.Info.PayInDate));
                    $('#txtPayNumber').textbox('setText', jsData.Info.PayInNumber);
                    $('#txtPayPerson').textbox('setText', jsData.Info.PayInPerson);
                    $('#txtPayRemark').textbox('setText', jsData.Info.Remark);
                   
                    $('#txtAmountPayable').numberbox('setValue', jsData.Info.AmountPayable);//应解金额
                    $('#txtPayMoney').numberbox('setValue', jsData.Info.PaymentAmount);    //解款金额
                    $('#txtUnPaidMoney').numberbox('setValue', jsData.Info.UnPaidAmount); //应解未缴
                    $('#txtSubmitTime').datebox('setValue', $.formatDate(jsData.Info.SubmitDate));//add20190613 plq 凭证上交日期
                }
                else {

                    $('#txtAmountPayable').numberbox('setValue', jsData.Info.PaidMoney); //应解金额
                }


                if (jsData.timeOut) {
                    $('#timeOut').html('已超时，停止更改');
                    $('#txtPayTime').datebox('readonly', true);
                    $('#txtPayNumber').textbox('readonly', true);
                    $('#txtPayPerson').textbox('readonly', true);
                    $('#txtPayRemark').textbox('readonly', true);

                    $('#txtAmountPayable').numberbox('readonly', true);
                    $('#txtPayMoney').numberbox('readonly', true);
                    $('#txtUnPaidMoney').numberbox('readonly', true);

                    $('#txtSubmitTime').datebox('readonly', true);//add20190613 plq 凭证上交日期


                }
            }
        });
    }

    function submitPay() {  //提交编辑

        $.ajax({
            type: 'POST',
            url: '@Url.Content("~/DD/DriverReport/SubmitPay")',
            data:
                {
                    RowID: $('#PayInID').val(),
                    PayTime: $('#txtPayTime').datebox("getValue"),
                    PayNumber: $('#txtPayNumber').textbox("getText"),
                    PayPerson: $('#txtPayPerson').textbox("getText"),
                    PayRemark: $('#txtPayRemark').textbox("getText"),

                    AmountPayable: $('#txtAmountPayable').numberbox("getValue"),
                    PayMoney: $('#txtPayMoney').numberbox("getValue"),
                    UnPaidMoney: $('#txtUnPaidMoney').numberbox("getValue"),

                    SubmitTime: $('#txtSubmitTime').datebox("getValue")//add20190613 plq 凭证上交日期
                },
            dataType: "json",
            success: function (jsData) {
                $.handleJsonResult(jsData, function () {
                    $('#ReportPayIn').dialog('close');
                    $("#DriverReportMain").datagrid("reload"); //重新加载 司机日报表 页面主列表数据
                });
            }
        });
    }

</script>
<div id="ReportPayIn" class="easyui-dialog" title="请输入解款内容" data-options="modal:true,
    collapsible:false,
    minimizable:false,
    maximizable:true,
    closed:true,
    resizable:true,
    iconCls:'icon-custom-cDelivery',
    onClose:function(){ deletePayInRow();}" style="width: 40%; height: 350px; padding: 0px; ">
    @*<div data-options="region:'center',title:'回访',iconCls:'icon-custom-cPrice'">*@
    <div id="paytb" style="padding: 5px; height: auto">
        <table style="width:99%" cellpadding="5" cellspacing="0" border="0">
            <tr>
                <td align="right">应解金额：</td>
                <td align="left">
                    <input id="txtAmountPayable" class="easyui-numberbox" style="width: 250px;" data-options="precision:0,prefix:'￥',readonly:true">
                </td>
            </tr>
            <tr>
                <td align="right">解款金额：</td>
                <td align="left">
                    <input id="txtPayMoney" class="easyui-numberbox" style="width: 250px;" data-options="precision:0,prefix:'￥'">
                </td>
            </tr>
            <tr>
                <td align="right">应解未缴：</td>
                <td align="left">
                    <input id="txtUnPaidMoney" class="easyui-numberbox" style="width: 250px;" data-options="precision:0,prefix:'￥',readonly:true">
                </td>
            </tr>
            <tr>
                <td align="right">解款日期：</td>
                <td align="left">
                    <input type="hidden" id="PayInID" />
                    <input class="easyui-datebox" style="width:250px" id="txtPayTime" data-options="editable:false">
                    <span id="timeOut" style="color:red;"></span>
                </td>
            </tr>
            <!--20190613 plq 增加凭证上交日期-->
            <tr>
                <td align="right">凭证上交日期：</td>
                <td align="left">
                    <input class="easyui-datebox" style="width:250px" id="txtSubmitTime" data-options="editable:false">
                </td>
            </tr>
            <tr>
                <td align="right">解款单号：</td>
                <td align="left">
                    <input class="easyui-textbox" style="width:250px" id="txtPayNumber">
                </td>
            </tr>
            <tr>
                <td align="right">解款人：</td>
                <td align="left">
                    <input class="easyui-textbox" style="width: 250px" id="txtPayPerson">
                </td>
            </tr>
            <tr>
                <td align="right">备注：</td>
                <td align="left">
                    <input class="easyui-textbox" style="width: 250px" id="txtPayRemark">
                </td>
            </tr>
            <tr>
                <td></td>
                <td align="left">
                    &nbsp;&nbsp;
                    <a href="javascript:void(0)" id="btnsearch" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="submitPay();">提交</a>
                </td>

            </tr>
        </table>
    </div>
</div>
